﻿@using Himall.Model;
@using Himall.Web.Areas.SellerAdmin.Models;

@model IEnumerable<ProductInfo>
@{
    ViewBag.Title = ViewBag.keywords + "  商品搜索";
}

<script type="text/javascript">
        $(function ()
        {
            $.ajax({
                type: 'get',
                url: '/ProductPartial/GetBrowedProduct',
                data: {},
                dataType: 'json',
                cache: true,// 开启ajax缓存
                success: function (data)
                {
                    if (data)
                    {
                        //console.log(data);
                        var html = '';
                        for (var i = 0; i < data.length; i++)
                        {
                            var text = ' <li><a href="/Product/Detail/' + data[i].ProductId + '" title="' + data[i].ProductName + '"><img  src="' + data[i].ImagePath + '/1_100.png" /></a></li>';
                            html += text;
                        }
                        $("#_bList").prepend($(html));
                    }
                },
                error: function (e)
                {
                    //alert(e);
                }
            });
        });

    </script>
<script type="text/javascript">
    $(function () {
        $('.v-option .o-more').click(function () {
            if ($(this).hasClass('fold')) {
                $(this).removeClass('fold').html('<b></b>更多');
                $(this).parent().siblings().addClass('v-unfold');
            } else {
                $(this).addClass('fold').html('<b></b>收起');
                $(this).parent().siblings().removeClass('v-unfold');
            }
        });
        $('.a-values').each(function () {
            var h = $(this).find('.v-fold').height();
            if (h > 25) {
                $(this).find('.v-option').show();
                $(this).find('.v-fold').addClass('v-unfold');
            } else {
                $(this).find('.v-option').hide();
            }
        });




        //关注商品
        $(".btn-coll").click(function () {
            var gid = $(this).attr('gid');
            checkLogin(function (func) {
                addFavoriteFun(gid, func);
            });
        });

    });
    function addFavoriteFun(gid, callBack) {
        $.post('/Product/AddFavoriteProduct', { pid: gid }, function (result) {
            if (result.successful == true) {
                if (result.favorited == true) {
                    $.dialog.alert('<p><em>' + result.mess +'</em></p>');
                } else {
                    $.dialog.succeedTips(result.mess, null, 0.5);
                }
            }
            (function () { callBack && callBack(); })();

        });
    }




    function checkLogin(callBack) {
        var memberId = $.cookie('Himall-User');
        if (memberId) {
            callBack();
        }
        else {
            $.fn.login({}, function () {
                callBack(function () { location.reload(); });
            }, '', '', '/Login/Login');
        }
    }

    $(function () {
        $("#searchBox").val("@ViewBag.keywords");
    });
</script>



<div class="w main">
    @if (null != Model && Model.Count() != 0)
    {
        <div class="crumb">全部结果&nbsp;&gt;&nbsp;<strong>"@ViewBag.keywords"</strong></div>
        <div class="left">
            <div class="m" id="refilter">
                <div class="mt">
                    <h2>所有类目</h2>
                </div>
                <div class="mc">
                    @{
        if (null != ViewBag.Category)
        {
            foreach (var item in ((List<Himall.Web.Areas.SellerAdmin.Models.CategoryJsonModel>)ViewBag.Category))
            {
                <div class="item fore hover">
                    <h3>
                        <b></b>
                        <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = item.Id,b_id = ViewBag.b_id,a_id = ViewBag.a_id,orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})" class="@(item.Id == ViewBag.cid.ToString()?"curr":"")">@item.Name</a>
                    </h3>
                    <ul>
                        @foreach (var sub in item.SubCategory)
                        {

                            <li class="@(sub.Id == ViewBag.cid.ToString() ? "curr" : "")">
                                <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = sub.Id,b_id = ViewBag.b_id,a_id = ViewBag.a_id,orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})">@sub.Name</a>
                            </li>
                        }
                    </ul>
                </div>
            }
        }
                    }
                    @*<div class="extra">
                            <a href="javascript:;" class="more">
                                <span>显示全部分类</span><b class="open"></b>
                            </a>
                        </div>*@
                </div>
            </div>
        </div>
        <div class="right-extra">
            <div class="clr"></div>
            <div class="m" id="select">
                <div class="mt">
                    <h1>@ViewBag.keywords &nbsp;&nbsp;<strong>商品筛选</strong></h1>
                    <div class="total">
                        <span>(共<strong id="res_count">@(Model == null ? 0 : Model.Count())</strong>个商品)</span>
                    </div>
                </div>
                <div class="mc attrs">
                    @if (ViewBag.b_id != 0 || !string.IsNullOrWhiteSpace(ViewBag.a_id))
                    {
                        <div class="selected-c">
                            <div class="attr">
                                <div class="a-key">已选条件：</div>
                                <div class="a-values">
                                    <div class="v-fold">
                                        <ul class="f-list">
                                            @if (ViewBag.b_id != 0)
                                            {
                                                <li>
                                                    <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = 0,a_id = ViewBag.a_id,orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})" title="@ViewBag.BrandName">品牌：<strong>@ViewBag.BrandName</strong><b></b></a>
                                                </li>
                                            }
                                            @if (!string.IsNullOrWhiteSpace(ViewBag.a_id))
                                            {
                                                if (((Dictionary<string, string>)ViewBag.AttrDic).Count() == 1)
                                                {
                                                    var dic = (Dictionary<string, string>)ViewBag.AttrDic;
                                                    <li>
                                                        <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_id,orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})" title="">@dic.ElementAt(0).Key.Split(':')[0]：<strong>@dic.ElementAt(0).Key.Split(':')[1]</strong><b></b></a>
                                                    </li>
                                                }
                                                else
                                                {
                                                    foreach (var item in (Dictionary<string, string>)ViewBag.AttrDic)
                                                    {
                                                        <li>
                                                            <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_id,a_id = item.Value,orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})" title="">@item.Key.Split(':')[0]：<strong>@item.Key.Split(':')[1]</strong><b></b></a>
                                                        </li>
                                                    }
                                                }
                                            }

                                        </ul>
                                    </div>
                                    <div class="v-option">
                                        <span id="all-revocation">
                                            <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = 0,a_id = "",orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})">全部撤消</a>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    }
                    @if (ViewBag.b_id == 0)
                    {
                        if (null != ViewBag.Brands && ((List<BrandInfo>)ViewBag.Brands).Count() > 0)
                        {
                            <div class="prop-attrs brand-attr">
                                <div class="attr">
                                    <div class="a-key">品牌：</div>
                                    <div class="a-values">
                                        <div class="v-fold">
                                            <ul class="f-list">
                                                @{
                            foreach (var brand in ((List<BrandInfo>)ViewBag.Brands))
                            {
                                <li>
                                    <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = brand.Id,a_id = ViewBag.a_id,orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})">@brand.Name</a>
                                </li>
                            }
                                                }
                                            </ul>
                                        </div>
                                        <div class="v-option">
                                            <span class="o-more"><b></b>更多</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        }
                    }
                    <div class="prop-attrs">
                        @{if (null != ViewBag.Attrs)
                        {
                            foreach (var attr in ((List<TypeAttributesModel>)ViewBag.Attrs))
                            {
                                bool isbreak = false;
                                foreach (var val in ((Dictionary<string, string>)ViewBag.AttrDic).Values)
                                {
                                    var ids = val.Replace('@', '_').Split('_');
                                    if (ids.Contains(attr.AttrId.ToString()))
                                    {
                                        isbreak = true;
                                        break;
                                    }
                                }
                                if (isbreak) { continue; }
                                <div class="attr">
                                    <div class="a-key">@attr.Name：</div>
                                    <div class="a-values">
                                        <div class="v-fold v-unfold">
                                            <ul class="f-list">
                                                @foreach (var attrV in attr.AttrValues)
                                                {
                                                    <li>
                                                        <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_Id,a_id = attr.AttrId+"_"+attrV.Id+"@"+ (string)ViewBag.a_id,orderType = ViewBag.orderType,orderKey = ViewBag.orderKey})">@attrV.Name</a>
                                                    </li>
                                                }
                                            </ul>
                                        </div>
                                        <div class="v-option">
                                            <span class="o-more fold"><b></b>收起</span>
                                        </div>
                                    </div>
                                </div>
                            }
                        }
                        }
                    </div>
                    <div class="clr"></div>
                </div>
                @*<div class="mb" id="advanced">
                        <div class="attr-extra"><div>更多选项（肤质，价格）<b></b></div></div>
                    </div>*@
            </div>
            @{
                        var count = ((PagingInfo)ViewBag.pageInfo).TotalPages;
                        var curr = ((PagingInfo)ViewBag.pageInfo).CurrentPage;
            }
            <!--显示已选条件及属性-->
            <div class="clr"></div>
            <div id="filter">
                <div class="fore1">
                    <dl class="order">
                        <dt>排序：</dt>
                        <dd class="@(ViewBag.orderKey==1?"curr":"")"><a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_Id,a_id =ViewBag.a_id,orderType = 2,orderKey = 1})" onclick="">相关度</a><b></b></dd>
                        <dd class="@(ViewBag.orderKey==2?"curr":"")">
                            <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_Id,a_id =ViewBag.a_id,orderType = 2,orderKey = 2})">成交量</a><b></b>
                        </dd>
                        <dd class="@(ViewBag.orderKey==3?"curr":"")">
                            <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_Id,a_id =ViewBag.a_id,orderType = ((int)ViewBag.orderType) == 2 ? 1 : 2,orderKey = 3})">价格</a><b></b>
                        </dd>
                        <dd class="@(ViewBag.orderKey==4?"curr":"")">
                            <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_Id,a_id =ViewBag.a_id,orderType = 2,orderKey = 4})">评论数</a><b></b>
                        </dd>
                        <dd class="@(ViewBag.orderKey==5?"curr":"")">
                            <a href="@Url.Action("Index", "Search", new{pageNo=1,keywords = ViewBag.keywords,exp_keywords = ViewBag.exp_keywords,cid = ViewBag.cid,b_id = ViewBag.b_Id,a_id =ViewBag.a_id,orderType = 2,orderKey = 5})">上架时间</a><b></b>
                        </dd>
                    </dl>
                    <dl class="stock-search">
                        <dt>
                            <input class="text-stock-search" id="text-stock-search" type="text" autocomplete="off" title="在结果中搜索" value="@ViewBag.exp_keywords">
                        </dt>
                        <dd>
                            <input class="btn-stock-search" id="btn-stock-search" type="button" value="确定">
                        </dd>
                    </dl>
                    <div class="pagin pagin-m" id="top_pagi">
                        <span class="text"><i>@curr</i>/@count</span>
                    </div>
                    <span class="clr"></span>
                </div>

            </div>

            <div class="m psearch prebuy plist-n7 no-preview" id="plist">
                <ul class="list-h cl">
                    @foreach (var product in Model ?? new List<ProductInfo>())
                    {

                        <li>
                            <div class="lh-wrap">
                                <div class="p-img">
                                    <a target="_blank" href="@Url.Action("Detail", "Product", new { id = product.Id })">
                                        <img class="lazyload" src="~/Areas/Web/images/blank.gif" data-url="@product.ImagePath/1_220.png">
                                    </a>
                                    <div shop_id="0"></div>
                                </div>
                                <div class="p-price">
                                    <strong>￥@product.MinSalePrice.ToString("f2")</strong>
                                    <label style="float:right" id="lblOrderCount_@product.Id">成交 <b> @product.SaleCounts </b>笔</label>
                                </div>
                                <div class="p-name">
                                    <a target="_blank" href="@Url.Action("Detail", "Product", new { id = product.Id })">
                                        @if (!string.IsNullOrWhiteSpace(ViewBag.keywords))
                                        {
                                            string newProductName = string.Empty;
                                            string[] keywords = ((string)ViewBag.keywords).Replace("\t", " ").Replace("　", " ").Split(' ');
                                            bool found = false;
                                            for (var i = 0; i < product.ProductName.Length; i++)
                                            {
                                                found = false;
                                                foreach (var keyword in keywords)
                                                {
                                                    if (!string.IsNullOrWhiteSpace(keyword))
                                                    {
                                                        if (product.ProductName.Substring(i).ToUpper().StartsWith(keyword.ToUpper()))
                                                        {
                                                            newProductName += "<font class='keycolor'>" + product.ProductName.Substring(i, keyword.Length) + "</font>";
                                                            i += keyword.Length-1;
                                                            found = true;
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (!found)
                                                {
                                                    newProductName += product.ProductName[i];
                                                }
                                            }
                                            @MvcHtmlString.Create(newProductName);
                                        }
                                        else
                                        {
                                            @product.ProductName
                                        }
                                    </a>
                                </div>

                                <div class="p-price">
                                    <label style="float:left;width:125px;" id="lblShopName_@product.Id">@product.ShopName</label>
                                    <label style="float:right;" id="lblShopAddress_@product.Id">@product.Address</label>
                                </div>
                             
                            </div>
                        </li>
                    }
                </ul>
            </div>
            <div class="m clearfix" id="bottom_pager">
                <div id="pagin-btm" class="pagin fr">
                    @Html.PageLinks((PagingInfo)ViewBag.pageInfo, x => Url.Action("Index", new { pageNo = x, keywords = ViewBag.keywords, exp_keywords = ViewBag.exp_keywords, cid = ViewBag.cid, b_id = ViewBag.b_id, a_id = ViewBag.a_id, orderType = ViewBag.orderType, orderKey = ViewBag.orderKey }))<span class="page-skip">
                        <em>&nbsp;&nbsp;共 </em><em id="pageCount">@count</em><em>&nbsp;页&nbsp;&nbsp;&nbsp;&nbsp;到第</em>
                        <input class="jumpto" type="text" value="@curr" id="jumpInput">
                        <em>页</em>
                        <a class="btn-skipsearch" id="pageJump" href="javascript:;">确定</a>
                    </span>
                </div>
            </div>
            <div id="re-search" class="m">
                <dl>
                    <dt>重新搜索</dt>
                    <dd>
                        <input type="text" class="text" id="key-re-search" value="@ViewBag.keywords">
                        <input type="button" class="button" id="btn-re-search" value="搜&nbsp;索">
                    </dd>
                </dl>
            </div>
        </div>
        <span class="clr"></span>
    }
    else
    {
        <div class="w main">
            <div class="notice-search">
                <span class="ns-icon"></span>
                <div class="ns-content">
                    <span>抱歉，没有找到与“<em>@(ViewBag.keywords + (string.IsNullOrWhiteSpace(ViewBag.exp_keywords) ? "" : "_" + ViewBag.exp_keywords))</em>”相关的商品</span>
                </div>
            </div>
        </div>
        <div class="w footmark">

            <div class="m recent-view">
                <div class="mt">
                    <h2 class="title">最近浏览</h2>

                </div>
                <div class="mc">
                    <ul class="recent-view-list clearfix">
                        @if (null != ViewBag.BrowsedHistory)
                        {
                            foreach (var item in (List<Himall.Web.Areas.Web.Models.ProductBrowsedHistoryModel>)ViewBag.BrowsedHistory)
                            {
                                if (item != null)
                                {
                                    <li>
                                        <div class="p-img">
                                            <a href="@Url.Action("Detail", "Product", new { id = item.ProductId })" title="" target="_blank">
                                                <img class="lazyload" src="~/Areas/Web/images/blank.gif" data-url="@item.ImagePath/1_100.png" alt="" width="70px" height="70px" />
                                            </a>
                                        </div>
                                        <div class="p-price">￥@item.ProductPrice.ToString("f2")</div>
                                    </li>
                                }
                            }
                        }
                    </ul>
                </div>
            </div>
        </div>
    }

    <input type="hidden" id="logined" value="@ViewBag.Logined" />
</div>
